package com.tsing.cedap.rest.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsing.cedap.rest.entity.ReceivingAddressEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tsing.cedap.rest.vo.respVo.IdAndNameRespVo;
import com.tsing.cedap.rest.vo.respVo.MiniGetAddressByIdRespVo;
import com.tsing.cedap.rest.vo.respVo.MiniGetAddressPageRespVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 收件地址表 Mapper 接口
 * </p>
 *
 * @author TheTsing
 * @since 2022-01-26
 */
public interface ReceivingAddressMapper extends BaseMapper<ReceivingAddressEntity> {

    @Select("select ra.id,ra.name,ra.phone,ra.address,c.name campus,ra.weight\n" +
            "from cedap_receiving_address ra\n" +
            "inner join cedap_campus c on ra.campus_id=c.id\n" +
            "where ra.user_id=#{id}\n" +
            "order by ra.weight asc,ra.id desc")
    List<MiniGetAddressPageRespVo> miniGetAddressPage(IPage<MiniGetAddressPageRespVo> page, @Param("id") String id);

    @Select("select ra.id,ra.name,ra.phone,ra.address,ra.campus_id,ra.weight,c.name campusName,s.name schoolName\n" +
            "from cedap_receiving_address ra\n" +
            "inner join cedap_campus c on ra.campus_id=c.id\n" +
            "inner join cedap_school s on c.school_id=s.id\n" +
            "where ra.id=#{id}")
    MiniGetAddressByIdRespVo miniGetAddressById(@Param("id") String code);

    @Select("select ra.id,concat(c.name,' - ',ra.address) name\n" +
            "from cedap_receiving_address ra\n" +
            "inner join cedap_campus c on ra.campus_id=c.id\n" +
            "where ra.user_id=#{id}\n" +
            "order by ra.weight asc,ra.id desc")
    List<IdAndNameRespVo> addressList(@Param("id") String id);

}
